package com.seamtop.cuber.web.controller.data;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.seamtop.cuber.common.base.DataObject;
import com.seamtop.cuber.common.entriy.*;
import com.seamtop.cuber.common.params.ParamsCalibration;
import com.seamtop.cuber.common.util.ParamsUtil;
import com.seamtop.cuber.common.util.StringUtil;
import com.seamtop.cuber.web.echarts.builder.ChartContext;

import com.seamtop.cuber.web.echarts.builder.impl.Pie7ChartAdapter;
import com.seamtop.cuber.web.service.CuberDataService;
import com.seamtop.cuber.web.service.ESDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by zongjunfeng on 2015/11/5.
 */

@Controller("CuberDataController")
public class CuberDataController {

    @Autowired
    private CuberDataService cuberDataService;

    @RequestMapping("/cuber/search.shtml")
    public @ResponseBody
        String search(HttpServletRequest request, HttpServletResponse response,
                                  ModelMap model) {
        HashMap<String,String> paramMap = ParamsUtil.transRequestToMap(request);
        System.out.println("paramMap:"+paramMap);
        HttpReturn checkOk = ParamsCalibration.validate(ValidateConstants.VALIDATE_ID_SEARCH, paramMap);
        JSONObject resultObject = new JSONObject();
        String reducerName = paramMap.get("reducer");
        int displayType = Integer.valueOf(paramMap.get("displayType"));
        String temp = cuberDataService.buildChart(reducerName,displayType);
        System.out.println("temp:"+temp);
        return temp;
    }

    @RequestMapping("/cuber/search1.shtml")
    public @ResponseBody
    String search1(HttpServletRequest request, HttpServletResponse response,
                  ModelMap model) {
        HashMap<String,String> paramMap = ParamsUtil.transRequestToMap(request);
        System.out.println("paramMap:"+paramMap);
        HttpReturn checkOk = ParamsCalibration.validate(ValidateConstants.VALIDATE_ID_SEARCH, paramMap);
        JSONObject resultObject = new JSONObject();
        String reducerName = paramMap.get("reducer");
        String data = cuberDataService.buildTable(reducerName);
        System.out.println("data:"+data);
        return data;
    }
}
